<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>确认付款</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" href="../css/style.css" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
	</head>

	<body>
		<div class="mui-content qrfuk_content">
			<div class="fuk_conbox">
				<div class="fuk_ctop">
					<div class="fuk_ctimg"><img id='store_thum'></div>
					<div class="fuk_spnam"></div>
				</div>
				<div class="fuk_center">
					<div>消费金额</div>
					<div class="fuk_pribox">
						<label>¥</label>
						<input id='pay_money' readonly="readonly"  type="text"></input>
					</div>
					<!--<div class="fuk_jif">
	    			<p>您本次可以使用鼓励金抵消费额度</p>
	    			<p class="fuk_jifnum"><em>80</em>鼓励金</p>
	    		</div>-->
				</div>
				<p class="liuy">
					<a href="#">添加留言</a>
				</p>
				<button type="button" class="qrfuk_btn" id='qrfuk_btn'>确认付款</button>
			</div>
			<div class="fuk_sm">©由龙信云商铺提供技术支持</div>
		</div>
		<!----------------悬浮框  设置支付密码 ------------------->
		<div class="mask">
			<div class="mask_con">
				<div class="top">
					<span class="del"><button type="button">X</button></span>
					<span class="tx"><img src="../images/cpimg.jpg"></span>
					<span class="wz">请输入支付密码</span>
				</div>
				<div class="xf_pribox">
					<p class="xf_fknam">向“<em>爱上漂亮美业</em>”付款</p>
					<p class="xf_pri">¥<em>100</em></p>
				</div>
				<div class="xffkfs">
					<a href="#"><span class="img"><img src="../images/jinbi.gif"></span>使用鼓励金支付</a>
				</div>
				<div class="xfk_btn"><button type="button">设置支付密码</button></div>
			</div>
		</div>
		<!----------------悬浮框  填写支付密码------------------->
		<div class="mask" style="display: none;">
			<div class="mask_con">
				<div class="top">
					<span class="del"><button type="button">X</button></span>
					<span class="tx"><img src="../images/cpimg.jpg"></span>
					<span class="wz">请输入支付密码</span>
				</div>
				<div class="xf_pribox">
					<p class="xf_fknam">向“<em>爱上漂亮美业</em>”付款</p>
					<p class="xf_pri">¥<em>100</em></p>
				</div>
				<div class="xffkfs">
					<a href="#"><span class="img"><img src="../images/jinbi.gif">
				</span>使用鼓励金支付</a>
				</div>
				<div class="pwd-box">
					<input type="tel" maxlength="6" class="pwd-input" id="pwd-input">
					<div class="fake-box">
						<input type="password" readonly="">
						<input type="password" readonly="">
						<input type="password" readonly="">
						<input type="password" readonly="">
						<input type="password" readonly="">
						<input type="password" readonly="">
					</div>
				</div>
			</div>
			<div id="callback"></div>
			<div id="cut_back"></div>
		</div>
		<input type="hidden" id='order_sn'>
	</body>

</html>
<script src="../js/mui.min.js"></script>
<script src="../js/zepto.min.js"></script>
<script type="text/javascript" src="../js/date.js"></script>

<script type="text/javascript" src="../js/jquery.min.js"></script>
<script type="text/javascript" src="../js/layer/layer.min.js"></script>
<script type="text/javascript" src="../js/app.js"></script>
<script>
	$(function() {
		//记录扫码客户端，微信，或支付宝
		var pay_type = 0;
		var ua = window.navigator.userAgent.toLowerCase();
		var access_code = getQueryString("code");
		var auth_code = getQueryString("auth_code");
		var openid = localStorage.getItem('openid');
		if(ua.match(/MicroMessenger/i) == 'micromessenger') {
			if(!openid){
				getOpenId();
			}
			pay_type = 3;
		} else if(ua.match(/AlipayClient/i) == 'alipayclient') {
			pay_type = 4;
			if(auth_code == null) {
				var fromurl = location.href;
				var url = 'https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2088021044805134&scope=auth_user&redirect_uri='+encodeURIComponent(fromurl);
				location.href = url;
			}
		}
		
		if(pay_type == 4){
			var res = alipay_user(auth_code,getUrlParam("fromuid"));
		}
		order_id= getUrlParam("oid");
		//获取商户信息
		$.ajax({
			url: APP.api_url + 'wallet/get_payinfo',
			data: {
				order_id: order_id
			},
			success: function(data) {
				if(data.code == 200) {
					var order=data.order;
					sessionStorage.setItem("cut_store_info", JSON.stringify(data.data)); 
					$("#pay_money").val(order.price);
					$('.fuk_spnam').text(data.data.store_name)
					
					//图片地址
					var picture_url = user_tupian(data.data.store_logo,'../images/cpimg.jpg');
					$("#store_thum").attr('src', picture_url);
				} else {
					layer.msg('该店铺不存在');
					return false;
				}
			}
		})
		//确认付款
		$("#qrfuk_btn").click(function() {
			$("#qrfuk_btn").attr("disabled", true);
			//获取用户信息
			var pay_money = $("#pay_money").val();
			var act = "alipay";
			var jstype = "html";

			var cut_pay_money = pay_money;
			

			if(pay_type == 3) {
				act = "wechat";
				jstype = "jsonp";
			}
			
			var sn = getSn();
			$('#order_sn').val(sn);
			$.ajax({
				url: APP.api_url + 'Payment/' + act,
				data: {
					WIDout_trade_no	: sn,
					WIDsubject		: "二维码付款",
					WIDtotal_fee	: cut_pay_money,
					//WIDtotal_fee	: 0.01,
					WIDshow_url		: 'www',
					WIDbody			: "二维码付款",
					uid				: getUid(),
					order_ids		: order_id,
					type			: "xs_order",
					user_type		: 1,
					pay_money		: pay_money,
					token			: get_token(),
					openid			: openid,
					pay_type		: pay_type
				},
				type: "post",
				dataType: jstype,
				jsonp: 'callback',
				jsonpCallback: 'jsonpCallback',
				success: function(data) {
					if(pay_type == 3) {
						callpay(data);
					} else {
						$("#callback").append(data);
					}
				}
			})
		});

	});

	function jsonpCallback(data) {
		$("#cut_back").append(data);
	}
	//调用微信JS api 支付
	function jsApiCall(jsApiParameters) {
		WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParameters,
			function(res) {
				if(res.err_msg == "get_brand_wcpay_request:ok") {
					layer.msg('付款成功！', {
						  time: 2000 
						}, function(){
							location.href="success.html?order_id="+order_id;
						});
				} else {
					layer.msg('付款失败');
				}
			});
	}

	function callpay(jsApiParameters) {
		console.log(jsApiParameters);
		if(typeof WeixinJSBridge == "undefined") {
			if(document.addEventListener) {
				document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsApiParameters), false);
			} else if(document.attachEvent) {
				document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsApiParameters));
				document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsApiParameters));
			}
		} else {
			jsApiCall(jsApiParameters);
		}
	}
</script>